from PyQt5 import QtCore
from PyQt5.QtWidgets import *
import sys

class CustWidget(QWidget):
    def __init__(self,parent=None):
        super(CustWidget,self).__init__(parent)
        self.okButton=QPushButton("ok",self)
        self.okButton.setObjectName("okbutton")
        layout=QHBoxLayout()
        layout.addWidget(self.okButton)
        self.setLayout(layout)
        QtCore.QMetaObject.connectSlotsByName(self)#
    @QtCore.pyqtSlot()
    def on_okbutton_clicked(self):
        print("被点击了")

    '''
     def __init(self,parent=None):
        self.okButton.connect(self.okbutton_clicked)
     def okbutton_clicked(self):
        print(点击)
    '''
if __name__ == '__main__':
    app=QApplication(sys.argv)
    win=CustWidget()
    win.show()
    sys.exit(app.exec_())